/**webSocket通讯管理类 */
class webNetworkMananger {
	/**是否连接 */
	public isConnecteed: boolean;
	/**是否为真人对决 */
	public isMoving: boolean;
	public constructor() {

	}
	/**心跳 */
	private hertBeatTimer: egret.Timer;
	/**单例对象 */
	private static instance: webNetworkMananger;
	public static getInstance(): webNetworkMananger {
		if (this.instance == null) {
			this.instance = new webNetworkMananger();
		}
		return this.instance;
	}
	/**是否是自己的回合 */
	public isMyLeg: boolean = false;
	/**击球状态 */
	public hitBallType: number = 0;
	private roomId = 0;
	/**服务器球的位置 */
	public serverBallPoint: NewBall[] = [];
	/**服务器回合 */
	public serverRoundNumber: number = 0;
	/**本地回合数 */
	public roundNumber: number;
	/**我方超时计数 */
	private timeoutcount: number = 0;
	/**循环计时器 */
	public loopTimer: egret.Timer = new egret.Timer(1000 / 60, 0);
	/**是否可以同步 */
	public isCanSync: boolean = false;
	/**心跳 */
	private heartTimer() {
		// this.hertBeatTimer = new egret.Timer(1000, -1);
		// this.hertBeatTimer.addEventListener(egret.TimerEvent.TIMER, e => {
		// 	if (this.isConnecteed == true)
		// 		webNetworkMananger.getInstance().SendMeesage('hert', {});
		// }, this);
		// this.hertBeatTimer.start();
	}
	/**游戏是否结束 */
	public isGameOver: boolean = false;


	//游戏场景
	public gameSceneRec: TableUI;
	/**服务器移动 */
	private _root_url: string = "127.0.0.1";
	/**是否联网模式 */
	public static isServerMove: boolean = false;
	private webSocket: egret.WebSocket;
	/**断线重连定时器 */
	public lineTimer: egret.Timer = new egret.Timer(5000, 0);
	/**球袋数组 */
	public intoBallIdxArr: NewBall[] = [];
	/**是否正在重连 */
	public isReconnecting: boolean = false;
	/**建立连接 */
	public connect(): void {
		if (this._root_url === null) {
			console.error("未设置连接HOST IP");
			return;
		}
		this.webSocket = new egret.WebSocket();
		//设置数据格式为二进制，默认为字符串
		//	this.webSocket.type = egret.WebSocket.TYPE_BINARY;
		//添加收到数据侦听，收到数据会调用此方法
		this.webSocket.addEventListener(egret.ProgressEvent.SOCKET_DATA, this.onReceiveMessage, this);
		//添加链接打开侦听，连接成功会调用此方法
		this.webSocket.addEventListener(egret.Event.CONNECT, this.onSocketOpen, this);
		//添加链接关闭侦听，手动关闭或者服务器关闭连接会调用此方法
		this.webSocket.addEventListener(egret.Event.CLOSE, this.onSocketClose, this);
		//添加异常侦听，出现异常会调用此方法
		this.webSocket.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onSocketError, this);

		//this.webSocket.connectByUrl('ws://172.16.19.104:8084/ws');			//本地测试用
		this.webSocket.connectByUrl('ws://114.115.147.97:8084/ws');				//外网

	}
	/**发送登陆信息 */
	public sendLoginData() {
		var tt = {
			msgId: 1001,
			userId: 174363,
			name: "王石",
			sex: 1,
			headUrl: "周润发"
		};
		tt.name = randomName.getInstance().getRandomName();
		if (GameData.myUserData != null) {
			tt.userId = GameData.myAccount;
		}
		TableUI.Instance().setSour('Welcome ' + tt.name);
		this.SendMeesage(JSON.stringify(tt));
		this.cleartimeoutcount();
	}
	/**连接成功 */
	public onSocketOpen(): void {
		this.isConnecteed = true;
		TableUI.Instance().setSour('Welcome Back');
		if (this.lineTimer.running == true) {
			TableUI.Instance().breakLineMsgShow("重连成功。。。");
			this.lineTimer.stop();
			this.lineTimer.removeEventListener(egret.TimerEvent.TIMER, this.breakLineReconnection, this);
			this.lineTimer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE, this.reconnectionTimeout, this);
			egret.setTimeout(e => {
				TableUI.Instance().breakLineShow.visible = false;
				this.sendBreakReconnectionMsg();
			}, this, 500);
		} else {
			if (!this.isReconnecting) {
				this.gameSceneRec.waitingMatch();
				console.log("连接成功");
				this.sendLoginData();
			}
		}
	}
	public sendBreakReconnectionMsg() {
		var tt = {
			msgId: 1010,
			userId: GameData.myAccount,
			name: "王石",
			sex: 1,
			headUrl: "周润发"
		};
		this.SendMeesage(JSON.stringify(tt));
	}
	/**连接失败 */
	public onSocketClose(): void {
		this.isConnecteed = false;
		/**房间内重连 */
		if (this.isMoving) {
			if (!this.isReconnecting) {
				this.isReconnecting = true;
				//预留断线重连显示
				this.lineTimer = new egret.Timer(5000, 4);
				this.lineTimer.addEventListener(egret.TimerEvent.TIMER, this.breakLineReconnection, this);
				this.lineTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.reconnectionTimeout, this);
				this.lineTimer.start();
			}
		} else {
			TableUI.Instance().homeServer = FakeServerManage.getInstance();
			TableUI.Instance().matchSuccessful();
			console.log("连接失败,开启AI模式");
			TableUI.Instance().setSour('开启AI模式');
		}
	}
	/**重连超时 */
	public reconnectionTimeout() {
		this.lineTimer.stop();
		this.lineTimer.removeEventListener(egret.TimerEvent.TIMER, this.breakLineReconnection, this);
		this.lineTimer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE, this.reconnectionTimeout, this);
		egret.setTimeout(e => {
			TableUI.Instance().breakLineShow.visible = false;
			TableUI.Instance().judgeSuccessFailure(false);
			console.log("我方掉线，对方胜");
			TableUI.Instance().setSour('lost connection');
		}, this, 500);
	}
	/**断线重连 */
	public breakLineReconnection() {
		TableUI.Instance().breakLineMsgShow("断线重连中。。。");
		this.connect();
	}
	/**连接报错 */
	public onSocketError(): void {
		console.log("连接报错");

	}
	/**发送消息（二进制） */
	public SendBitMeesage(mes: egret.ByteArray): void {
		this.webSocket.writeBytes(mes);
		this.webSocket.flush();
	}
	/**发送消息 */
	public SendMeesage(msg: string): void {
		this.webSocket.writeUTF(msg);
	}
	/**发送摆球消息 */
	public sendPutBallMsg(point) {
		var data = {
			msgId: 1006,
			userId: GameData.myUserData.userId,
			roomId: GameData.roomId,
			x: point.x,
			y: point.y
		}
		this.SendMeesage(JSON.stringify(data));
	}
	/**发送击球消息 */
	public SendShootMeesage(shootInfo): void {
		var tt = {
			msgId: 1003,
			userId: GameData.myUserData.userId,
			vx: shootInfo.vx,
			vy: shootInfo.vy,
			roomId: GameData.roomId
		};
		this.cleartimeoutcount();
		this.SendMeesage(JSON.stringify(tt));

	}
	/**发送杆的消息 */
	public SendMoveMeesage(moveData): void {

		var tt = {
			msgId: 1004,
			userId: GameData.myUserData.userId,
			x: moveData.point.x,
			y: moveData.point.y,
			angle: moveData.angle,
			roomId: GameData.roomId
		};

		this.SendMeesage(JSON.stringify(tt));
	}
	/**交换球权消息 */
	public SendShootEndMeesage(type, userId): void {
		let data = {
			ballPoint: TableUI.Instance().ballArr,
			roundNumber: this.roundNumber
		}
		var tt = {
			msgId: 1005,
			userId: GameData.myUserData.userId,
			serveOrder: userId,
			serverOrderType: type,
			ballPoint: JSON.stringify(data),
			ballShow: JSON.stringify(TableUI.Instance().golfBag),
			roomId: GameData.roomId
		};
		TableUI.Instance().countdownFunc(true, 30);
		this.SendMeesage(JSON.stringify(tt));

		//*勿删
		// if (TableUI.Instance().isComBoPK && TableUI.Instance().isComBoOK) {//联网 连杆特效
		// 	this.numii++;
		// 	console.log("numii进球", this.numii);
		// 	TableUI.Instance().ShowComBo(TableUI.Instance().hole,this.numii);
		// } else {
		// 	this.numii = 0;
		// }
	}
	/**连杆计数 */
	// public numii: number = 0;
	/**停止游戏循环 */
	public stopGameLoop() {
		this.loopTimer.stop();
		this.loopTimer.removeEventListener(egret.TimerEvent.TIMER, this.dealWithBallSync, this);
		this.roundNumber = 0;
		this.serverBallPoint = [];
		this.serverRoundNumber = -1;
		this.isCanSync = false;


	}
	/**发送获胜消息 */
	public sendWinUserId(winUserId) {
		var data = {
			msgId: 1008,
			userId: GameData.myUserData.userId,
			winUserId: winUserId,
			grade: 0,
			roomId: GameData.roomId
		}
		this.SendMeesage(JSON.stringify(data));
	}
	/**确定花色 */
	public confirmColor(colorOne, colorTwo) {
		var data = {
			msgId: 1007,
			userId: GameData.myUserData.userId,
			colorOne: colorOne,
			colorTwo: colorTwo,
			roomId: GameData.roomId
		}
		this.SendMeesage(JSON.stringify(data));

		if (colorOne == 0) {
			TableUI.Instance().setSour('word11');//我是全色
		}
		else {
			TableUI.Instance().setSour('word12');//我是花色
		}
	}
	/**发送摆白球消息 */
	public sendBaiPoint(point, putBallType) {
		var data = {
			msgId: 1011,
			userId: GameData.myUserData.userId,
			roomId: GameData.roomId,
			type: putBallType,
			x: point.x,
			y: point.y
		}
		this.SendMeesage(JSON.stringify(data));
	}
	/**发送表情 */
	public sendFace(type) {
		var data = {
			msgId: 1009,
			userId: GameData.myUserData.userId,
			type: type,
			roomId: GameData.roomId
		}
		console.log("发送表情" + type);
		this.SendMeesage(JSON.stringify(data));
	}

	/**接受消息 */
	public onReceiveMessage(e: egret.Event): void {
		// var byte: egret.ByteArray = new egret.ByteArray();
		// this.webSocket.readBytes(byte);
		/**收到的消息 */
		var msg = this.webSocket.readUTF();
		if (msg == "") { return; }
		/**解析后的消息 */
		var obj = JSON.parse(msg);
		let msgid = obj.msgId;
		//登陆消息
		if (obj.msgId == 1101) {
			GameData.myAccount = obj.userId;
			console.log("新生成的ID：" + obj.userId);
			//this.gameSceneRec.waitingMatch();
		}
		//匹配成功，开始游戏
		if (obj.msgId == 1102) {
			if (obj.suc) {//如果匹配成功
				this.roundNumber = 0;
				let data = [];
				/**玩家1信息 */
				var userOneDate = {
					userId: obj.userIdOne,
					name: obj.nameOne,
					sex: obj.sexOne,
					headUr: obj.headUrlOne
				}
				data.push(userOneDate);
				/**玩家2信息 */
				var userTwoDate = {
					userId: obj.userIdTwo,
					name: obj.nameTwo,
					sex: obj.sexTwo,
					headUrl: obj.headUrlTwo
				}
				data.push(userTwoDate);
				for (let i = 0; i < data.length; i++) {
					if (data[i].userId == GameData.myAccount) {
						GameData.myUserData = data[i];
					} else {
						GameData.rivalUserData = data[i];
					}
				}
				TableUI.Instance().SMShowPlayerData();
				this.loopTimer = new egret.Timer(1000 / 60, 0);
				this.loopTimer.addEventListener(egret.TimerEvent.TIMER, this.dealWithBallSync, this);
				this.loopTimer.start();
				GameData.roomId = obj.roomId;
				/**预留状态
				 * 1-摆球
				 * 2-自由球
				 * 3-击球
				 */
				var serverOrderType = obj.serverOrderType;
				this.gameSceneRec.matchSuccessful();
				if (obj.serveOrder == GameData.myAccount) {
					TableUI.Instance().changeType(1);
					TableUI.Instance().myLeg = true;
					this.isMyLeg = true;
					console.log("首杆我方回合");
					TableUI.Instance().ld.visible = true;
					TableUI.Instance().slipgroup.visible = true;
					TableUI.Instance().MyRange.touchEnabled = true;
					changeBG("resource/assets/bg/tableR.png");
					TableUI.Instance().setSour('word15');
				} else {
					TableUI.Instance().myLeg = false;
					this.isMyLeg = false;
					console.log("首杆对方回合");
					TableUI.Instance().ld.visible = false;
					TableUI.Instance().slipgroup.visible = false;
					TableUI.Instance().setSour('word7');
				}
				TableUI.Instance().isFirstLeg = true; //第一回合
				this.isMoving = true;
			} else {
				TableUI.Instance().homeServer = FakeServerManage.getInstance();
				TableUI.Instance().startGame1();
				console.log("匹配失败,开启AI模式");
				TableUI.Instance().setSour('Match Failed  AI mode started');
			}

		}
		/**击球 */
		if (obj.msgId == 1103) {
			var curDate = {
				vx: obj.vx,
				vy: obj.vy
			}
			TableUI.Instance().SMTOHit(curDate);
		}
		/**杆的移动 */
		if (obj.msgId == 1104) {
			var moveGanData = {
				point: { x: obj.x, y: obj.y },
				angle: obj.angle
			}
			TableUI.Instance().SMCue(moveGanData);
			TableUI.Instance().ShowGanImg();
		}
		/**交换球权 */
		if (obj.msgId == 1105) {
			this.roundNumber++;
			console.log("交换球权   1105");
			//TableUI.Instance().shootBallShow.text = null;
			let data = JSON.parse(obj.ballPoint);
			/**球的位置 */
			let ballPoint: NewBall[] = data.ballPoint;
			this.serverRoundNumber = data.roundNumber;
			let ballShow: NewBall[] = JSON.parse(obj.ballShow);
			this.serverBallPoint = ballPoint;
			this.intoBallIdxArr = ballShow;
			//this.dealWithBallSync();			
			this.dealShootOrder(obj.serveOrder, obj.serverOrderType);

			var isme = obj.serveOrder == GameData.myAccount;
			this.isMyLeg = isme;
			//console.log(isme, "  i s   m e ");
			// TableUI.Instance().myLeg = isme;
			// TableUI.Instance().isOwnGame = isme;
			switch (obj.serverOrderType) {
				case 1://线后自由球
					if (isme)//给我的 对方  rivalUserData
					{
						TableUI.Instance().setSour("word9");//对方击球犯规 你获得线后自由球
						changeBG("resource/assets/bg/tableR.png");//发球区域
						console.log("你获得 线后 自由球");
					} else {
						TableUI.Instance().setSour("word10");//击球犯规 对方线后自由球
						console.log("对方 线后 自由球");
						TableUI.Instance().HideGanImg();
						setBaiPos(-17, -17);
					}
					break;
				case 2://自由球
					if (isme)//给我的 对方  rivalUserData
					{
						TableUI.Instance().setSour("word5");//对方击球犯规 你获得自由球
						console.log("对方击球犯规 你获得自由球");
					} else {
						TableUI.Instance().setSour("word4");//击球犯规 对方自由球
						TableUI.Instance().HideGanImg();
						console.log("击球犯规 对方自由球");
						setBaiPos(-17, -17);
					}
					break;
				case 3://正常回合
					if (isme)//给我的 对方  rivalUserData				
					{
						TableUI.Instance().setSour("word6");//玩家回合
						console.log("正常击球 我的回合");
					} else {
						TableUI.Instance().setSour('word7');//对方回合
						console.log("正常击球 对方回合");
					}
					break;
				default:
					console.log("Unknow obj type" + obj.serverOrderType);
			}
			TableUI.Instance().countdownFunc(true, 30);
		}
		/**摆球 */
		if (obj.msgId == 1106) {
			var point = {
				x: obj.x,
				y: obj.y
			}
			TableUI.Instance().SMPutBall(point);
			TableUI.Instance().ShowGanImg();
			TableUI.Instance().ClearW();
			console.log("摆球  1106");
		}
		/**确定花色 */
		if (obj.msgId == 1107) {
			console.log("确定花色  1107");
			if (obj.colorOne == GameData.myUserData.userId) {
				TableUI.Instance().myColor = 0;

				TableUI.Instance().SMColor(0);//实心
				TableUI.Instance().setSour('word11');//您本局为全色
			} else {
				TableUI.Instance().myColor = 1;
				TableUI.Instance().SMColor(1);
				TableUI.Instance().setSour('word12');//您本局为花色
			}
		}
		/**判断胜负 */
		if (obj.msgId == 1108) {
			this.stopGameLoop();
			console.log("判断胜负  1108");
			this.isGameOver = true;
			if (obj.winUserId == GameData.myAccount) {
				console.log("收到 捷报")
				//自己获胜
				egret.setTimeout(() => {
					TableUI.Instance().judgeSuccessFailure(true);

				}, this, 100);
			} else {
				console.log("收到 战败")
				//对方获胜
				egret.setTimeout(() => {
					TableUI.Instance().judgeSuccessFailure(false);

				}, this, 100);
			}
		}
		/**表情 */
		if (obj.msgId == 1109) {
			/**表情状态 */
			let faceType = obj.type;
			console.log("接收表情" + faceType);
			TableUI.Instance().ShowFace(faceType);//显示接收到的表情
		}
		/**断线重连消息 */
		if (obj.msgId == 1110) {
			console.log("断线重连  1108");
			this.isReconnecting = false;
			let data = {
				shootID: obj.serveOrder,
				shootType: obj.serverOrderType,
				ballPoint: JSON.parse(obj.ballPoint),
				ballShow: JSON.parse(obj.ballShow)
			}
			this.serverBallPoint = data.ballPoint;
			this.dealWithBallSync();
			this.intoBallIdxArr = data.ballShow;
			if (this.intoBallIdxArr.length > 0) {
				for (let i = 0; i < this.intoBallIdxArr.length; i++) {
					TableUI.Instance().showBall(this.intoBallIdxArr[i].idx);
				}
			}
			//预留同步进球状态
			if (data.shootID == GameData.myAccount) {
				TableUI.Instance().changeType(data.shootType);
				this.isMyLeg = true;
				TableUI.Instance().myLeg = true;
			} else {
				TableUI.Instance().isOwnGame = false;
				TableUI.Instance().myLeg = false;
				this.isMyLeg = false;
			}

		}
		/**显示对方摆放白球的操作 */
		if (obj.msgId == 1111) {
			let data = {
				stageX: obj.x,
				stageY: obj.y
			}
			TableUI.Instance().SMmoveWhiteball(data, obj.type);
		}

		//报错信息
		if (obj.msgId == 100) {
			let data = {
				errorcontext: obj.errorcontext,
				shootID: obj.shootID,
				shootType: obj.shootType,
				LostUserId: obj.LostUserId
			}
			this.showErrorMessage(data.errorcontext);
		}
		/**对方超时处理 */
		if (obj.msgId == 101) {
			console.log("对方超时  101");
			TableUI.Instance().clearnowCombox();//清空连进计数器
			let data = {
				errorcontext: obj.errorcontext,
				shootID: obj.shootID,
				shootType: obj.shootType,
				LostUserId: obj.LostUserId
			}
			if (data.shootID == -1) {
				console.log("对方玩家跑了");
			}

			let shootId;
			TableUI.Instance().ClearAllLine();//清除所有瞄准线
			TableUI.Instance().ClearW();
			if (data.shootID == GameData.myAccount) {
				shootId = GameData.rivalUserData.userId;
				console.log("我方超时，对方回合");
				this.timeoutcount++;
				console.warn("您已经超时 ", this.timeoutcount, " 次, 再超时 ", (3 - this.timeoutcount), " 次后将判输");
				if (this.timeoutcount > 2) {
					webNetworkMananger.getInstance().sendWinUserId(GameData.rivalUserData.userId);
					console.warn("我方超时3次 判输");
				}
				// TableUI.Instance().OppositeRound();
				TableUI.Instance().countdownFunc(false);//停止计时器
				TableUI.Instance().setSour('word3');
				TableUI.Instance().countdownFunc(true, 30);
				TableUI.Instance().isBaiqiu = 0;
				TableUI.Instance().isOwnGame = false;
				TableUI.Instance().HideGanImg();
				TableUI.Instance().ClearAllLine();
				TableUI.Instance().ClearW();
				TableUI.Instance().OppositeRound();
			} else {
				shootId = GameData.myAccount;
				console.log("对方超时，我方回合");
				TableUI.Instance().MyRound();
				TableUI.Instance().setSour('Your opponent`s kicking is overtime,and you get the free ball');
				TableUI.Instance().countdownFunc(true, 30);
				TableUI.Instance().LighttoMyBalls();
			}
			if (shootId == GameData.myAccount) {
				if (TableUI.Instance().isFirstLeg) {
					TableUI.Instance().changeType(1);
					console.log("线后自由球!")
					changeBG("resource/assets/bg/tableR.png");
					TableUI.Instance().isBaiqiu = 1;
				} else {
					TableUI.Instance().changeType(data.shootType);
					TableUI.Instance().isBaiqiu = 2;
				}
				TableUI.Instance().myLeg = true;
				this.isMyLeg = true;
				// TableUI.Instance().lightning(0);
			} else {
				TableUI.Instance().isOwnGame = false;
				TableUI.Instance().myLeg = false;
				this.isMyLeg = false;
				// TableUI.Instance().lightning(1);
				if (TableUI.Instance().isFirstLeg) {
					changeBG("resource/assets/bg/table.png");
				}
			}
			//this.dealShootOrder(shootId, data.shootType);
		}
		/**对方掉线我方胜利处理 */
		if (obj.msgId == 102) {
			console.log("对方掉线  102");
			let data = {
				errorcontext: obj.errorcontext,
				shootID: obj.shootID,
				shootType: obj.shootType,
				LostUserId: obj.LostUserId
			}
			this.isGameOver = true;
			this.stopGameLoop();
			if (data.LostUserId == GameData.myAccount) {
				TableUI.Instance().judgeSuccessFailure(false);
				console.log("我方掉线，对方胜");
				TableUI.Instance().setSour('lost connection');
			} else {
				TableUI.Instance().judgeSuccessFailure(true);
				console.log("对方掉线，我方胜利");
				TableUI.Instance().setSour('The opposet has lost connection You Win');
			}

		}

	}
	/**同步球的位置 */
	public dealWithBallSync() {
		if (this.isGameOver) {
			return;
		}
		if (!this.isCanSync) {
			return;
		}
		// if (this.roundNumber - 1 != this.serverRoundNumber) {
		// 	return;
		// }
		// TableUI.Instance().StopAllBall();
		if (this.serverBallPoint == null) {
			return;
		}
		if (this.serverBallPoint.length == 0) {
			return;
		}
		console.log("开始 同步  球的位置");
		/**同步球袋位置 */
		TableUI.Instance().golfBag = this.intoBallIdxArr;
		let serverBallPoint: NewBall[] = this.serverBallPoint;
		/**本地球的位置 */
		let homeBallPoint: NewBall[] = TableUI.Instance().ballArr;
		/**要添加的球 */
		let ballsToAdd: NewBall[] = [];
		/**要删除的球 */
		let ballsToRemove: NewBall[] = [];
		for (let i = 0; i < serverBallPoint.length; i++) {
			/**本地球下标 */
			let homeBallSub: number = this.findBall(serverBallPoint[i].idx, homeBallPoint);
			if (homeBallSub != null) {
				let homeBall: NewBall = homeBallPoint[homeBallSub];
				homeBall.isJindong = serverBallPoint[i].isJindong;
				if (homeBall.name == "cur" && homeBall.isJindong != -1) {
					continue;
				}
				if (homeBall.nextX != serverBallPoint[i].nextX || homeBall.nextY != serverBallPoint[i].nextY) {
					homeBall.lastX = serverBallPoint[i].lastX;
					homeBall.lastY = serverBallPoint[i].lastY;
					homeBall.nextX = serverBallPoint[i].nextX;
					homeBall.nextY = serverBallPoint[i].nextY;
					setBallPos1(homeBall.nextX, homeBall.nextY, homeBallSub);
					// setBallPos(homeBall.nextX, homeBall.nextY, homeBall.lastX, homeBall.lastY, homeBallSub);
					// refreshUI();
				}
			}

		}

		TableUI.Instance().BallArrToShow();
		this.serverBallPoint = [];
		this.serverRoundNumber = -1;
		this.isCanSync = false;
		console.log("同步完成");

		TableUI.Instance().myLeg = this.isMyLeg;
		//判断回合是否交换
		if (TableUI.Instance().myLeg) {
			TableUI.Instance().changeType(webNetworkMananger.getInstance().hitBallType);
			console.log("我的回合");
			TableUI.Instance().LighttoMyBalls();
			if (TableUI.Instance().lastshoot != GameData.myAccount) {
				// } else {
				TableUI.Instance().nowCombox = 0;
				console.log("changed ! ! !")
			}
			TableUI.Instance().lastshoot = GameData.myAccount;
			TableUI.Instance().ld.visible = true;
			TableUI.Instance().slipgroup.visible = true;
			TableUI.Instance().MyRange.touchEnabled = true;
		} else {
			TableUI.Instance().ld.visible = false;
			TableUI.Instance().slipgroup.visible = false;
			TableUI.Instance().MyRange.touchEnabled = false;
			console.log("对方的回合");
			if (TableUI.Instance().lastshoot != GameData.rivalUserData) {
				// } else {
				TableUI.Instance().nowCombox = 0;
				console.log("changed ! ! !")
			}
			TableUI.Instance().lastshoot = GameData.rivalUserData;
		}

	}
	/**通过IDX找球下标 */
	public findBall(ballIdx, homeBallPoint: NewBall[]) {
		for (let i = 0; i < homeBallPoint.length; i++) {
			if (homeBallPoint[i].idx == ballIdx) {
				return i;
			}
		}
	}
	/**显示错误信息 */
	public showErrorMessage(errorMessage: string) {
		//	this.gameSceneRec.errorMsgPopup(errorMessage);
	}
	// public numii: number = 0;
	/**处理先后顺序 */
	public dealShootOrder(serveOrder, type) {
		if (serveOrder == GameData.myAccount) {
			//TableUI.Instance().changeType(type);
			this.hitBallType = type;
			this.isMyLeg = true;
			//console.log("我的回合");
			// this.numii += TableUI.Instance().iii;
			// TableUI.Instance().ShowComBo(this.numii);

		} else {
			this.isMyLeg = false;
			//console.log("对方的回合");
		}

	}
	/**清除超时计数 */
	private cleartimeoutcount() {
		this.timeoutcount = 0;
	}


}